// pages/user/visitrecord/visitrecord.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navIndex:0, // 导航索引
        norecord: true,
        hiddenModal: true,
        dataList: [],
        swiperHeader: 2000,
        personalData: '',
        companyList:[],
        id: '',
    },
        // 切换导航
    changeNav:function(e){
        let index = e.currentTarget.dataset.index;
        this.setData({
            navIndex:index
        })
        if(this.data.navIndex == 1) {
            this.listdata();
        }
        
        
    },
    //个人发布列表
    listdata() {
        let _this = this;
        app.util.ajax({
            url: 'Platform/myVisit',
            data: {
                user_id: app.globalData.userInfo.user_id,
            },
            success: function(res) {
                _this.setData({
                    personalData: res.company,
                    companyList:res.enterprise
                })
            }
        })
    },
    Revoke(){
        wx.showToast({
            title: '撤销中'
        })
    },
    //发布结束后删除
    Release_end(e){
        // let id = e.currentTarget.dataset.id;
        let _this = this;
        wx.showModal({
            content: '是否删除走访？',
            success: function(res) {
                if (res.confirm) {
                    app.util.ajax({
                        url: 'platform/delete',
                        data: {
                            id: e.currentTarget.dataset.id
                        },
                        success: function(res) {
                            wx.showToast({
                                title: '删除成功'
                            })
                            setTimeout(()=>{
                                _this.listdata();
                            },1000)
                          
                        }
                    })
                }
            }
        })  
    },
    //申请撤销 
    listenerButtonss(e) {
       let id = e.currentTarget.dataset.id;
        let _this = this;
        wx.showModal({
            content: '是否向平台申请撤销该走访？',
            success: function(res) {
                if (res.confirm) {
                    app.util.ajax({
                        url: 'platform/cancel',
                        data: {
                            id: e.currentTarget.dataset.id
                        },
                        success: function(res) {
                            wx.showToast({
                                title: '撤销成功'
                            })
                            setTimeout(()=>{
                                _this.listdata();
                            },1000)
                          
                        }
                    })
                }
            }
        })
    },
    listenerButton(e) {
        let id = e.target.dataset.id,
            _this = this;
        wx.showModal({
            content: '是否取消走访申请',
            success: function(res) {
                if (res.confirm) {
                    app.util.ajax({
                        url: 'user/zf_record',
                        data: {
                            user_id: app.globalData.userInfo.user_id,
                            id: id
                        },
                        success: function(res) {
                            _this.getDataList();
                            wx.showToast({
                                title: '取消成功'
                            })
                        }
                    })
                }
            }
        })
    },
    listenerConfirm() {
        this.setData({
            hiddenModal: true
        })
    },
    listenerCancel() {
        this.setData({
            hiddenModal: true
        })
    },
    dtatilstype(e) {
        wx.navigateTo({
            url: '/pages/user/visitrecord/visit_details/visit_details'
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        //  高度自适应
        // wx.getSystemInfo({
        //     success: function(res) {
        //         var clientHeight = res.windowHeight,
        //             clientWidth = res.windowWidth,
        //             rpxR = 750 / clientWidth;
        //         var calc = clientHeight * rpxR - 180;
        //         that.setData({
        //             winHeight: calc
        //         });
        //     }
        // });
        this.getDataList();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    // 分享
    onShareAppMessage(res) {
        return {
            title: '广州大学校友会校友企业家专委会',
            path: '/pages/index/index'
        }
    },
    // 获取列表
    getDataList: function() {
        let _this = this;
        app.util.ajax({
            url: 'user/zf_record',
            data: {
                user_id: app.globalData.userInfo.user_id
            },
            success: function(res) {
                let data = [],
                    stateArr = ['申请中', '已通过', '已拒绝'];
                for (var i = 0, len = res.info.length; i < len; i++) {
                    let obj = res.info[i];
                    obj.stateTxt = stateArr[obj.state];
                    data.push(obj);
                }
                let bool = res.info.length != 0 ? false : true;
                _this.setData({
                    dataList: data,
                    norecord: bool
                })
            }
        })
    },
    // 查看名片
    getUserCard: function(e) {
        let id = e.currentTarget.dataset.id,
            type = e.currentTarget.dataset.usertype,
            _this = this;
        wx.navigateTo({
            url:'/pages/user/personal/personal?id='+id+'&state='+type
        })
    }
})